package com.lhy.tool.database.converter.oracle;

import com.lhy.tool.database.DbColumnType;

import java.util.function.Function;
import java.util.regex.Pattern;

public class OracleNumberConverter implements Function<String, DbColumnType> {

    private static final Pattern INTEGER = Pattern.compile("number\\(+\\d\\)");

    private static final Pattern LONG = Pattern.compile("number\\(+\\d{2}+\\)");

    @Override
    public DbColumnType apply(String s) {
        if (INTEGER.matcher(s).find()) {
            return DbColumnType.INTEGER;
        } else if (LONG.matcher(s).find()) {
            return DbColumnType.LONG;
        } else {
            return DbColumnType.DOUBLE;
        }
    }
}
